package com.gyul.findmystock.db;

import android.util.Log;


public class DataAccessObject<T> {
	String TAG = "DataAccessObject";
	static int count = 0;
	static DatabaseHelper helper = null;
	
	public DataAccessObject(String tag) {
		TAG = tag;
		acquire();
		
	}
		
	public synchronized void acquire() {
		//Log.d(TAG, "acquire()");
		
		if ( helper == null ) {
			Log.d(TAG, "Acquire New Helper");
			helper = new DatabaseHelper();
		}
		
		count++;
	}
	
	public synchronized void release() {
		//Log.d(TAG, "release()");
		
		count--;
		
		if ( count == 0 ) {
			Log.d(TAG, "close Helper");
			helper.close();
			helper = null;
		}
	}	
}
